import { Component, OnInit} from '@angular/core';

import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { SubmaterialManageService } from './submaterial-manage.service';

import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { Data } from '@angular/router';
import { DatePipe } from '@angular/common';
import { HCommonService } from 'src/app/h-common/h-common.service';
import { ignoreElements } from 'rxjs/operators';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-submaterial-manage',
  templateUrl: './submaterial-manage.component.html',
  styleUrls: ['./submaterial-manage.component.scss']
})
export class SubmaterialManageComponent implements OnInit {


  formatterPercent = (value: number) => `${!value ? "" : value} %`;
  parserPercent = (value: string) => value.replace(' %', '');
  private deleteModal: NzModalRef;
  modelType: number = 1;//模态框类型
  searchCode: string = '';//输入物料编码
  searchName: string = '';//输入物料名称
  isZc: any = "";//是否抽称
  isPc: any = "";//是否批次
  isJy: any = "";//是否检验
  isOkLoading: boolean = false;

  isAllDisplayDataChecked = false;
  isSearch: boolean = false;//是否是搜索
  current: any = 1;//table当前页
  pageIndex: any = 1;//提交的页码
  pagesize: any = 10;//table每页条数
  totalSize: any = '';//总共条数
  listOfDisplayData = [];
  isVisible: boolean = false;
  subSavementForm: FormGroup;
  listOfMapData = [];
  bottomListOfData = [];
  private editItem: any;

  code = <string>"";
  name = <string>"";
  unit = <string>"";
  category = <string>"";
  price: number = 0;
  costPrice: number = 0;
  spec: number = null;
  validDay: number = 0;
  purchaser: string = "";
  isBatch: boolean = false;
  isCheck: boolean = false;
  isWeight: boolean = false;
  checkDays: number = 0;
  weightRate: any = 0;
  abc: string = "";
  remarks: string = "";

  bucketCode: string = "";
  bucketName: string = "";
  inkMarkCode: string = "";
  inkMarkName: string = "";
  coverPaperCode: string = "";
  coverPaperName: string = "";
  csn: string = "";
 // expiryDate: any;
  psc: string;
  bornRoles = {};
  bornRolesSepc = {};

  modalDomBox:any;
  modalDomBoxGg:any;
  modalDomBoxInfo:any;
  modalSelDateList:any = [{value:0,label:'天'},{value:1,label:'月'},{value:2,label:'年'}];
  constructor(
    private submaterialManageService: SubmaterialManageService,
    private fb: FormBuilder,
    private modal: NzModalService,
    private datePipe: DatePipe,
    private commonService: HCommonService,
    private message: NzMessageService
  ) { }
  ngOnInit() {
    this.modalDomBox = document.querySelector("#modal_box");
    this.modalDomBoxGg = document.querySelector("#modal_boxGg");
    this.modalDomBoxInfo = document.querySelector("#modal_box_info");
    
     /* 获取权限 */
     this.bornRoles = this.commonService.getRoles("material");
     this.bornRolesSepc = this.commonService.getRoles("materialspec");
    this.subSavementForm = this.fb.group({
      code: [null, [Validators.required]],
      name: [null, [Validators.required]],
      unit: [null, [Validators.required]],
      category: [null, [Validators.required]],
      price: [null, [Validators.required]],
      costPrice: [null, [Validators.required]],
      validDay: [null, []],
      modalSelDate:[0,[]],
      totalDate:[0,[]],
      // purchaser: [null, [Validators.required]],

      isBatch: [false],
      isCheck: [false],
      isWeight: [false],

      checkDays: [null],
      abc: [null],
      weightRate: [null],

      remarks: [null],


      bucketCode: [null],
      bucketName: [null],
      inkMarkCode: [null],
      inkMarkName: [null],
      coverPaperCode: [null],
      coverPaperName: [null],
      csn: [null],
     // expiryDate: [null],
      psc: [null]
    });
    this.getSearchList();

    //规格
    this.SpecForm = this.fb.group({
      AddSpec: [null, [Validators.required]],
      AddPackSize: [null, [Validators.required]],
      wareId: [null, [Validators.required]],
      areaId: [null, [Validators.required]]
    });

    // this.GetWareList();
    this.getClListAbc();
    this.getClList();
  }
  // 改变选择的天 月 年
  dateChange(e:any){
    if(e==0){
      this.subSavementForm.patchValue({
        totalDate: Number(this.subSavementForm.get('validDay').value)
      })
    }else if(e==1){
      this.subSavementForm.patchValue({
        totalDate: Number(this.subSavementForm.get('validDay').value)*30
      })
    }else if(e==2){
      this.subSavementForm.patchValue({
        totalDate: Number(this.subSavementForm.get('validDay').value)*360
      })
    }
  }
  validDayChange(e){
    let _dateType = this.subSavementForm.get('modalSelDate').value
    if(_dateType==0){
      this.subSavementForm.patchValue({
        totalDate: e
      })
    }else if(_dateType==1){
      this.subSavementForm.patchValue({
        totalDate: e * 30
      })
    }else if(_dateType==2){
      this.subSavementForm.patchValue({
        totalDate: e * 360
      })
    }
  }
  GetSearchPageList() {
    this.pageIndex = 1;
    this.getSearchList();
    this.SpecAddDisabled = true;
    this.GetSpecList("111");
  }
  private arrePx = "updateDate,desc";
  // 获取搜索后的列表
  getSearchList() {
    let data = {
      code: this.searchCode,
      name: this.searchName,
      isBatch: this.isPc,
      isCheck: this.isJy,
      isWeight: this.isZc,
      page: this.pageIndex - 1,
      size: this.pagesize,
      sort: this.arrePx,
      enabled:false
    }
    this.submaterialManageService.apiList(data).subscribe(res => {
      res.content.forEach(s => s.checked == false);
      this.listOfMapData = res.content
      this.totalSize = res.totalElements
    });
  }
  //#region 选择、分页
  clickPage(pageIndex) {
    this.pageIndex = pageIndex;
    this.SpecAddDisabled = true;
    this.handleSearch();
  }
  clickSize(pageSize) {
    this.pagesize = pageSize
    this.SpecAddDisabled = true;
    this.handleSearch();
  }
  selectedZc(data) {
    this.isZc = data;
    // this.getSearchList();
    this.GetSearchPageList();
  }
  selectedPc(data) {
    this.isPc = data;
    // this.getSearchList();
    this.GetSearchPageList();
  }
  selectedJy(data) {
    this.isJy = data;
    // this.getSearchList();
    this.GetSearchPageList();
  }

  onDateChange(result: Date): void {
    let time = this.formatDate(result)
    //this.expiryDate = time;
  }
  // 时间格式化
  formatDate(date) {
    return this.datePipe.transform(date, 'yyyy-MM-dd hh:mm:ss');
  }
  // 时间格式化
  formatDateYmr(date) {
    return this.datePipe.transform(date, 'yyyy-MM-dd');
  }
  //mapOfCheckedId: { [key: string]: boolean } = {};
  editDisabled: boolean = true;//修改按钮是否禁用
  deleteDisabled: boolean = true;
  EditListData = [];
  // deleteMember = [];
  isIndeterminate = false;
  numberOfChecked = 0;
  checkAll(value: boolean): void {
    this.listOfMapData.forEach(item => {
      item.checked = value;
    });
    if (value == true) {
      var count = this.listOfMapData.filter(s => s.checked);
      if (count.length != 0) {
        this.editDisabled = false;
        this.deleteDisabled = false;
      }
      if (count.length != 1) {
        this.editDisabled = true;
      }
    }
    else {
      this.editDisabled = true;
      this.deleteDisabled = true;
    }
  }
  refreshStatus(data): void {
    let _isAllCheck = true;
    this.listOfMapData.forEach(item => {
      if (!item.checked) {
        _isAllCheck = false;
      }
    })
    this.isAllDisplayDataChecked = _isAllCheck;


    this.numberOfChecked = this.listOfMapData.filter(item => item.checked).length;
    // 判断能否编辑或删除
    if (this.numberOfChecked > 0) {
      this.deleteDisabled = false
    } else {
      this.deleteDisabled = true
    }
    if (this.numberOfChecked === 1) {
      this.editDisabled = false
    } else {
      this.editDisabled = true
    }

  }


  showModal(type, data?): void {
    this.modelType = type;
    this.isVisible = true;
    this.subSavementForm.reset();
    if (type == 1) {
      this.subSavementForm.patchValue({
        code: "",
        name: "",
        unit: "",
        category: "",
        price: 0,
        costPrice: 0,
        validDay: 0,
        modalSelDate:0,
        totalDate: 0,
        purchaser: "",
        isBatch: false,
        isCheck: false,
        isWeight: false,

        checkDays: 0,
        abc: "",
        weightRate: 0,
        remarks: "",
        bucketCode: "",
        bucketName: "",
        inkMarkCode: "",
        inkMarkName: "",
        coverPaperCode: "",
        coverPaperName: "",
        csn: "",
      //  expiryDate: null,
        psc: ""
      })
      return;
    }
    if (data) {
      this.subSavementForm.patchValue({
        code: data.code,
        name: data.name,
        unit: data.unit,
        category: data.category,
        price: data.price,
        costPrice: data.costPrice,
        validDay: data.validDay,
        modalSelDate:0,
        totalDate: data.validDay,
        purchaser: data.purchaser,
        isBatch: data.isBatch,
        isCheck: data.isCheck,
        isWeight: data.isWeight,

        checkDays: data.checkDays,
        abc: data.abc,
        weightRate: data.weightRate,
        remarks: data.remarks,
        bucketCode: data.bucketCode,
        bucketName: data.bucketName,
        inkMarkCode: data.inkMarkCode,
        inkMarkName: data.inkMarkName,
        coverPaperCode: data.coverPaperCode,
        coverPaperName: data.coverPaperName,
        csn: data.csn,
       // expiryDate: data.expiryDate,
        psc: data.psc
      })
      this.editItem = data;
    }
    else {
      var model = this.listOfMapData.filter(s => s.checked);
      if (model.length == 1) {
        var data = model[0];
        this.editItem = data;
        this.subSavementForm.patchValue({
          code: data.code,
          name: data.name,
          unit: data.unit,
          category: data.category,
          price: data.price,
          costPrice: data.costPrice,
          validDay: data.validDay,
          modalSelDate:0,
          totalDate: data.validDay,
          purchaser: data.purchaser,
          isBatch: data.isBatch,
          isCheck: data.isCheck,
          isWeight: data.isWeight,

          checkDays: data.checkDays,
          abc: data.abc,
          weightRate: data.weightRate,
          remarks: data.remarks,
          bucketCode: data.bucketCode,
          bucketName: data.bucketName,
          inkMarkCode: data.inkMarkCode,
          inkMarkName: data.inkMarkName,
          coverPaperCode: data.coverPaperCode,
          coverPaperName: data.coverPaperName,
          csn: data.csn,
        //  expiryDate: data.expiryDate,
          psc: data.psc
        })
      }
    }
  }
  // 确定按钮
  handleOk() {
    if (this.modelType == 1) {
      this.Addsubmaterial()
    }
    else {
      this.editSave("");
    }
  }
  deleteIds = [];
  handleDelete(ids?) {
    // if (!ids) {
    //   this.listOfMapData.forEach(s => {
    //     if (s.checked) {
    //       this.deleteIds.push(s.id);
    //     }
    //   });
    // }
    let delIdList = this.listOfMapData.filter(s => s.checked);

    // let _ids = ids || this.deleteIds;
    if (delIdList.length == 0) {
      this.modal.warning({
        nzTitle: "删除提示",
        nzContent: "请选择要删除的数据"
      })
      return false
    } else {
      var delIds = [];
      delIdList.forEach(item => {
        delIds.push(item.id);
      });
      this.modal.confirm({
        nzTitle: "删除提示",
        nzContent: "确定要删除这条数据吗？",
        nzOnOk: () => {
          this.delete(delIds);
        }
      })
    }
  }
  
  delete(id) {
    this.submaterialManageService.apiDelete(id).subscribe(res => {
      this.pageIndex = 0;
      this.getSearchList();
      this.GetSpecList("111");
      this.SpecAddDisabled = true;
      this.deleteModal.close();
    })
  }
 

  Addsubmaterial(): void {
    for (const i in this.subSavementForm.controls) {
      this.subSavementForm.controls[i].markAsDirty();
      this.subSavementForm.controls[i].updateValueAndValidity();
    }
    var eef = this.subSavementForm.invalid;
    var fa = this.subSavementForm.touched;
    if (this.subSavementForm.status == "VALID") {
      this.isOkLoading = true;
      let _value = this.subSavementForm.value;
      let _dataJson = {
        code: _value.code,
        name: _value.name,
        unit: _value.unit,
        category: _value.category,
        price: _value.price,
        costPrice: _value.costPrice,
        validDay: _value.totalDate,
        modalSelDate: _value.modalSelDate,
        totalDate: _value.totalDate,
        purchaser: _value.purchaser,
        isBatch: _value.isBatch,
        isCheck: _value.isCheck,
        isWeight: _value.isWeight,

        checkDays: _value.checkDays,
        weightRate: _value.weightRate,
        abc: _value.abc,
        remarks: _value.remarks,
        bucketCode: _value.bucketCode,
        bucketName: _value.bucketName,
        inkMarkCode: _value.inkMarkCode,
        inkMarkName: _value.inkMarkName,
        coverPaperCode: _value.coverPaperCode,
        coverPaperName: _value.coverPaperName,
        csn: _value.csn,
        // expiryDate: _value.expiryDate,
      //  expiryDate: this.expiryDate,
        psc: _value.psc,
      }
      console.log(_dataJson);
      this.submaterialManageService.add(_dataJson).subscribe(async res => {
        this.getSearchList();
        this.isOkLoading = false;
        this.handleCancel();
      }, () => {
        this.isOkLoading = false;
      });
    }
  }

  editSave(data: any) {
    let _dataJson = {}
    if (data !== "") {
      _dataJson = {
        ...data
      }
    } else {
      for (const i in this.subSavementForm.controls) {
        this.subSavementForm.controls[i].markAsDirty();
        this.subSavementForm.controls[i].updateValueAndValidity();
      }
      if (this.subSavementForm.status == "VALID") {
        this.isOkLoading = true;
        let _value = this.subSavementForm.value;
        let _dataJson = {
          id: this.editItem.id,
          code: _value.code,
          name: _value.name,
          unit: _value.unit,
          category: _value.category,
          price: _value.price,
          costPrice: _value.costPrice,
          spec: _value.spec,
          validDay: _value.totalDate,
          modalSelDate: _value.modalSelDate,
          totalDate: _value.totalDate,
          purchaser: _value.purchaser,
          isBatch: _value.isBatch,
          isCheck: _value.isCheck,
          isWeight: _value.isWeight,

          checkDays: _value.checkDays,
          weightRate: _value.weightRate,
          abc: _value.abc,
          remarks: _value.remarks,
          bucketCode: _value.bucketCode,
          bucketName: _value.bucketName,
          inkMarkCode: _value.inkMarkCode,
          inkMarkName: _value.inkMarkName,
          coverPaperCode: _value.coverPaperCode,
          coverPaperName: _value.coverPaperName,
          csn: _value.csn,
          // expiryDate: _value.expiryDate,
        //  expiryDate: this.expiryDate,
          psc: _value.psc,
        }
        console.log(_dataJson);
        this.submaterialManageService.edit(_dataJson).subscribe(async res => {
          this.getSearchList();
          this.isOkLoading = false;
          this.handleCancel();
        }, () => {
          this.isOkLoading = false;
        })
      }
    }
  }
  // 取消按钮
  handleCancel(): void {
    this.isVisible = false;
  }
  private isLoading = false;
  downloadList():void {
    this.modal.confirm({
      nzTitle: "获取ERP数据提示",
      nzContent: "确定要获取数据吗？",
      nzOnOk: () => {
        //事件
        this.isLoading = true;
        this.submaterialManageService.erpData().subscribe(res=>{
          this.isLoading = false;
          this.message.info("获取成功");
          this.handleSearch();
        },err=>{
          // let errorMessage = err.error.message
          // this.message.create("error", errorMessage)
          this.isLoading = false;
      });
      }
    })
   }
  handleSearch() {
    this.isSearch = true
    this.getSearchList();
    this.GetSpecList("111");

  }

  // 获取存料类型下拉菜单列表
  clList = [];
  async getClList() {
    let list: any = await this.submaterialManageService.getclTypeList('material_category');
    this.clList = list.content
  }
  // 获取存料类型下拉菜单列表
  clListAbc = [];
  async getClListAbc() {
    let list: any = await this.submaterialManageService.getclTypeList('material_abc_type')
    this.clListAbc = list.content
  }

  selectedCLModal(data) {
    this.category = data
  }
  selectedCLAbcModal(data) {
    this.abc = data
  }

  //#region 规格
  isViewWin: boolean = false;
  specIsAdd: boolean = false;
  SpecisOkLoading: boolean = false;
  SpecForm: FormGroup;

  AddSpec: any = null;
  AddPackSize: string = "";
  defaultKq: string = "";

  SpecIsAllChecked: boolean = false;

  SpecDeleteDisabled: boolean = true;
  SpecEditDisabled: boolean = true;
  SpecAddDisabled: boolean = true;

  private EditSepcId: string = "";
  checkSpecAll(value: boolean) {
    this.bottomListOfData.forEach(item => {
      item.checked = value;
    });
    if (value == true) {
      var count = this.bottomListOfData.filter(s => s.checked);
      if (count.length != 0) {
        this.SpecEditDisabled = false;
        this.SpecDeleteDisabled = false;
      }
      if (count.length != 1) {
        this.SpecEditDisabled = true;
      }
    }
    else {
      this.SpecEditDisabled = true;
      this.SpecDeleteDisabled = true;
    }
  }
  //添加
  SpecAdd() {
    this.GetWareList();
    this.specIsAdd = true;
    this.isViewWin = true;

    // this.AddSpec = null;
    // this.AddPackSize = "";
    // this.wareId = "";
    // this.areaId = "";



    this.SpecForm.reset();

    this.SpecForm.patchValue({
      AddSpec: null,
      AddPackSize: "",
      wareId: "",
      areaId: ""
    });
  }
  //修改
  SpecEdit() {
    this.specIsAdd = false;
    this.isViewWin = true;
    let editModel: any = this.bottomListOfData.filter(s => s.checked == true);
    if (editModel.length == 1) {
      this.SpecForm.patchValue({
        AddSpec: editModel[0].spec,
        AddPackSize: editModel[0].packSize,
        wareId: Number(editModel[0].warehouseId),
        areaId: editModel[0].warehouseAreaId,

      });
      this.EditSepcId = editModel[0].id

      // this.AddSpec = editModel[0].spec;
      // this.AddPackSize = editModel[0].packSize;
      // this.wareId = Number(editModel[0].warehouseId);
      // this.areaId = editModel[0].warehouseAreaId;
      // this.EditSepcId = editModel[0].id;
    }
    return editModel
  }
  //删除
  SpecDelete() {
    let delList: any = this.bottomListOfData.filter(s => s.checked == true);
    if (delList.length == 0) {
      this.modal.warning({
        nzTitle: "删除提示",
        nzContent: "请选择要删除的数据"
      })
      return false;
    }
    else {
      var ids = [];
      delList.forEach(e => {
        ids.push(e.id);
      });
      this.modal.confirm({
        nzTitle: "删除提示",
        nzContent: "确定要删除这条数据吗？",
        nzOnOk: () => {
          this.SpecDelMethod(ids);
        }
      })
    }
  }
  private SpecDelMethod(ids) {
    this.submaterialManageService.delSpec(ids).subscribe(res => {
      this.GetSpecList(this.materialId);
      this.SpecEditDisabled = true;
      this.SpecDeleteDisabled = true;
      this.deleteModal.close();
    })
  }
  //取消
  SpecCancel() {
    this.isViewWin = false;
  }
  //添加
  SpecSubmit() {
    for (const i in this.SpecForm.controls) {
      this.SpecForm.controls[i].markAsDirty();
      this.SpecForm.controls[i].updateValueAndValidity();
    }
    if (this.specIsAdd) {
      if (this.SpecForm.status == "VALID") {
        this.SpecisOkLoading = true;
        let _value = this.SpecForm.value;
        let _dataJson = {
          materialId: this.materialId,
          packSize: _value.AddPackSize,
          spec: _value.AddSpec,
          warehouseAreaId: _value.areaId
        }
        this.submaterialManageService.addSpec(_dataJson).subscribe(async res => {
          this.SpecisOkLoading = false;
          this.GetSpecList(this.materialId);
          this.SpecCancel();
        }, () => {
          this.SpecisOkLoading = false;
        });
      }
    }
    else {
      if (this.SpecForm.status == "VALID") {
        this.SpecisOkLoading = true;
        let _value = this.SpecForm.value;
        let _dataJson = {
          id: this.EditSepcId,
          materialId: this.materialId,
          packSize: _value.AddPackSize,
          spec: _value.AddSpec,
          warehouseAreaId: _value.areaId
        }
        this.submaterialManageService.editSpec(_dataJson).subscribe(async res => {
          this.SpecisOkLoading = false;
          this.GetSpecList(this.materialId);
          this.SpecCancel();
        }, () => {
          this.SpecisOkLoading = false;
        });
      }
    }
    this.SpecEditDisabled = true;
    this.SpecDeleteDisabled = true;
    this.SpecIsAllChecked = false;
  }
  SpecStatus() {
    let _isAllCheck = true;
    this.bottomListOfData.forEach(item => {
      if (!item.checked) {
        _isAllCheck = false;
      }
    })
    this.SpecIsAllChecked = _isAllCheck;


    var countSelect = this.bottomListOfData.filter(item => item.checked).length;
    // 判断能否编辑或删除
    if (countSelect > 0) {
      this.SpecDeleteDisabled = false
    } else {
      this.SpecDeleteDisabled = true
    }
    if (countSelect === 1) {
      this.SpecEditDisabled = false
    } else {
      this.SpecEditDisabled = true
    }
  }

  //库房列表
  wareList = [];
  wareId: any = "";
  GetWareList() {
    let data = {
      page: 0,
      size: 0,
      category:"料仓"
    }
    this.submaterialManageService.GetWareHouse(data).subscribe(res => {
      this.wareList = res.content;
    });
  }
  selectedWareModal(value: string): void {
    this.wareId = value;
    let t: any = this.wareList.filter(s => s.id == value);
    this.GetAreaList(value);
    if (this.EditSepcId == "" && t.length != 0) {
      //var modelSel = t[0].warehouseAreas;
      // this.areaId = modelSel[0].id;
    } else {
      let editModel: any = this.bottomListOfData.filter(s => s.checked == true);
      if (editModel.length != 0) {
        if (value != editModel[0].warehouseId) {
          // this.areaId = "";
          this.SpecForm.patchValue({
            areaId: "",
          });
        }
      }
    }
  }
  areaId: any = "";
  areaList = [];
  GetAreaList(value: any) {
    let t: any = this.wareList.filter(s => s.id == value);
    if (t.length == 0) {
      return;
    }
    this.areaList = t[0].warehouseAreas;

  }
  private materialId: string = "";
  

  
  //取得规格列表
  GetSpecList(value: string) {
    this.SpecIsAllChecked = false;
    this.materialId = value;
    let data = {
      materialId: value,
      page: 0,
      size: 1000
    };
    this.submaterialManageService.GetSpeList(data).subscribe(res => {
      res.content.forEach(d => d.checked == false);
      this.bottomListOfData = res.content;
      if (value != "111") {

        this.SpecAddDisabled = false;
      }
      else {
        this.bottomListOfData = [];
      }
    });

    this.GetStorageListById(value);
  }
  //#endregion

  //#region 详情
  isView: boolean = false;
  ViewData = [];
  GetModel(data) {
    this.isView = true;
    let data1 = {
      id: data.id
    }
    this.submaterialManageService.GetModel(data).subscribe(res => {
     // res.expiryDate = this.formatDateYmr(res.expiryDate);
      this.ViewData = res;
    });
  }
  ViewCancel() {
    this.isView = false;
  }
  //#endregion

  //#region 库房库区
  StorageRoomAreaList = [];
  GetStorageListById(value: string) {
    let data = {
      materialId: value,
      page: 0,
      size: 1000
    };
    this.submaterialManageService.GetStorageListById(data).subscribe(res => {
      this.StorageRoomAreaList = res.content;
    });
  }
  //#endregion


  requiredJyChange(required: boolean): void {
    if (!required) {
      this.subSavementForm.get('checkDays')!.clearValidators();
      this.subSavementForm.get('checkDays')!.markAsPristine();
    } else {
      this.subSavementForm.get('checkDays')!.setValidators(Validators.required);
      this.subSavementForm.get('checkDays')!.markAsDirty();
    }
    this.subSavementForm.get('checkDays')!.updateValueAndValidity();
  }

  requiredWeightChange(required: boolean): void {
    if (!required) {
      this.subSavementForm.get('weightRate')!.clearValidators();
      this.subSavementForm.get('weightRate')!.markAsPristine();
    } else {
      this.subSavementForm.get('weightRate')!.setValidators(Validators.required);
      this.subSavementForm.get('weightRate')!.markAsDirty();
    }
    this.subSavementForm.get('weightRate')!.updateValueAndValidity();
  }
}
